package com.wn.main.ui.category.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import com.wn.common.model.CategoryItem
import com.wn.framework.adapter.BaseBindViewHolder
import com.wn.framework.adapter.BaseRecyclerViewAdapter
import com.wn.main.databinding.CategoryTabItemBinding
import dagger.hilt.android.scopes.ActivityScoped
import javax.inject.Inject

/**
 * @Author: wn
 * @Date: 2025/3/26 15:58
 * @Description: 左侧 分类 list_tab Adapter
 */
@ActivityScoped
class CategoryTabAdapter @Inject constructor() :
  BaseRecyclerViewAdapter<CategoryItem, CategoryTabItemBinding>() {

  /**
   * 当前选中条目
   */
  private var selectedPosition = 0

  /**
   * 设置当前选中的 position
   * @param position Int   -- 当前选中的 position
   */
  fun setCurrentPosition(position: Int) {
    this.selectedPosition = position
  }

  /**
   * 子类通过 xml实现 ViewBinding，父类提供了 LayoutInflater ，viewType
   * 可以根据不同的 viewType传递不同的 viewBinding -- when
   */
  override fun getViewBinding(
    layoutInflater: LayoutInflater,
    parent: ViewGroup,
    viewType: Int,
  ): CategoryTabItemBinding = CategoryTabItemBinding.inflate(layoutInflater, parent, false)

  /**
   * 子类重写该方法绑定数据
   * 重写 [getViewBinding] 即可实现不同ViewHolder传递
   */
  override fun setViewBinding(
    holder: BaseBindViewHolder<CategoryTabItemBinding>,
    item: CategoryItem?,
    position: Int,
  ) {
    item?.apply {
      holder.binding.categoryItem = this
      holder.binding.position = position
      holder.binding.selectedPosition = selectedPosition
    }
  }
}